package com.yww.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.yww.entity.Modules;
import com.yww.entity.RoleModules;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author jobob
 * @since 2020-05-20
 */
public interface ModulesMapper extends BaseMapper<Modules> {
    /**
     * 根据模块id查询模块
     * @param modId
     * @return
     */
    @Select("select * from modules where mod_id=#{modId}")
    Modules getModulesByModId(Integer modId);

    /**
     * 根据用户id查询模块树
     * @param userId
     * @return
     */
    @Select("select * from modules\n" +
            "where mod_id in\n" +
            "(select mods_id from role_modules\n" +
            "where roles_id in\n" +
            "(select roles_id from user_roles\n" +
            "where users_id=#{userId}))")
    List<Modules> getModulesTreeByUserId(Integer userId);

    /**
     * 查询模块名称重复
     * @param modules
     * @return
     */
    @Select("select mod_name from modules")
    Modules getModName(Modules modules);

    @Select("select * from role_modules where mods_id=#{modId}")
    List<RoleModules> getRoleByModules(Integer modId);




}
